//
//  XZ_ScanQRCodeViewController.m
//  Project_Demo
//
//  Created by sisi on 2018/7/15.
//  Copyright © 2018年 caoxiaozhu. All rights reserved.
//

#import "XZ_ScanQRCodeViewController.h"

@interface XZ_ScanQRCodeViewController ()

@property(nonatomic,strong)UILabel *resultLabel;

@end

@implementation XZ_ScanQRCodeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 300, 300)];
    imageView.center = self.view.center;
    [self.view addSubview:imageView];
    
    NSString *cardName = @"天涯刀哥 - 傅红雪";
    UIImage *avatar = [UIImage imageNamed:@"avatar"];
    
    [HMScannerController cardImageWithCardName:cardName avatar:avatar scale:0.2 completion:^(UIImage *image) {
        imageView.image = image;
    }];
    
    _resultLabel = [[UILabel alloc]init];
    _resultLabel.frame = CGRectMake(0, 0, 100, 30);
    _resultLabel.textColor = Color_Black;
    [_resultLabel setOrigin:CGPointMake(imageView.center.x, CGRectGetMaxY(imageView.frame))];
    [self.view addSubview:_resultLabel];
    

    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [rightBtn setTitle:@"扫一扫" forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(clickToScan) forControlEvents:UIControlEventTouchUpInside];
    [rightBtn setSize:CGSizeMake(15, 15)];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem = item;

}

-(void)clickToScan{
    NSString *cardName = @"天涯刀哥 - 傅红雪";
    UIImage *avatar = [UIImage imageNamed:@"avatar"];
    
    HMScannerController *scanner = [HMScannerController scannerWithCardName:cardName avatar:avatar completion:^(NSString *stringValue) {
        
        self->_resultLabel.text = stringValue;
    }];
    
    [scanner setTitleColor:[UIColor whiteColor] tintColor:[UIColor greenColor]];
    
    [self showDetailViewController:scanner sender:nil];
}



@end
